package hdf5.parser;

import common.Range;

import java.util.ArrayList;
import java.util.List;

public class DataDivider {

    private long timeSteps;
    private long rowCounts;
    private final double [][] data;

    public DataDivider(double [][] data){
        this.data = data;
    }

    public void setTCountRowCount(long tCount, long rowCount) {
        timeSteps = tCount;
        rowCounts = rowCount;
        System.out.println("rowCounts:" + rowCounts + ", timeSteps:" + timeSteps);
    }


    public List<double[]> divideDataByDate() {
        List<double[]> dateList = new ArrayList<double[]>();
        for (int time = 0; time < timeSteps; time++) {
            double[] currentTimeData = new double[(int) rowCounts];
            for (int row = 0; row < rowCounts; row++) {
                currentTimeData[row] = data[row][time];
            }
            dateList.add(currentTimeData);
        }
        return dateList;
    }

    public Range getMaxMinValue() {
        Range range = new Range();
        range.setMin(Double.MAX_VALUE);
        range.setMax(Double.MIN_VALUE);
        for (int time = 0; time < timeSteps; time++) {
            for (int row = 0; row < rowCounts; row++) {
                range.setMax(Math.max(range.getMax(),data[row][time]));
                range.setMin(Math.min(range.getMin(),data[row][time]));
            }
        }
        return range;
    }

}
